package cn.akwangl.common;

/**
 * Http 请求统一响应包装类.
 *
 * @author youyongkun
 * @date 2022/5/17 13:43
 * @since 0.0.2
 */
public class Result<T> {
    /**
     * 响应业务状态
     */
    private Integer status;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应中的数据
     */
    private T data;

    public Result(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static <T> Result<T> createResult(Integer status, String msg, T data) {
        return new Result(status, msg, data);
    }

    public static <T> Result<T> success(T data) {
        return Result.createResult(200, "操作成功", data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return Result.createResult(200, msg, data);
    }

    public static Result errorMsg(String msg) {
        return Result.createResult(500, msg, null);
    }


    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
